#include <iostream>
using namespace std;
int  nums[100005];
int main()
{
  int  n = 0; cin>>n;
  int minn = 100000;
  for(int i = 1;i <= n;i++) {cin>>nums[i];
    minn = min(nums[i],minn);
  }
  long long ret = 0;
  for(int i = 1;i <= n;i++)
  {
    ret += nums[i] - minn;
  }
  cout << ret <<endl;
  return 0;
}
#include <iostream>
#include <string>
#include <set>
using namespace std;
int fun(const std::string& str) {
    int ret = 0;
    for (char c : str) {
        ret *= 2;
        ret += (c - '0');
    }
    return ret;
}

int main()
{
    int size = 0;
    string str;
    cin >> size; cin >> str;
    int len = 1;
    while (len <= size) {
        int left = 0, right = len - 1;
        set<int> ss;
        int t = 1 << (len - 1);
        if (len == 1)  t++;
        for (; right < size; right++, left++) {
            if (len != 1 && str[left] == '0') continue;
            ss.insert(fun(str.substr(left, len)));
            // cout << str.substr(left, len) << ' ';
            if (ss.size() == t)
                break;
        }
        if (ss.size() < t)
        {
            int begin = 1 << (len - 1), end = 1 << len;
            if (len == 1) begin = 0;

            while (ss.count(begin)) {
                begin++;
            }
            cout << begin << endl;
            return 0;
        }
        len++;
    }
    return 0;
}
#include <iostream>
#include <cmath>
using namespace std;
using ll = long long;
ll N = 998244353;
int main() {
    int t;  cin >> t;
    while (t--) {
        ll x;  cin >> x;
        ll n = (ll)sqrt(x + 1); // 取整
        ll ret = (n - 1) * n % N * (n + 1) % N;   // 前面完整的情况
        // 不完整情况
        int i = 0;
        while (n * (n + i) <= x)
            ret = (ret + n * (n + i++) ) % N;
        cout << ret << endl;
    }
}